﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.Model;
using Automobile.service.BLL;
using System.Data;

namespace Automobile.service.UI
{
    public partial class UpdateEmployee : System.Web.UI.Page
    {
        EmployeeBll bll = new EmployeeBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["fid"] != null)
                {
                    LoadData();
                }
            }
        }

        private void LoadData()
        {
            this.TextBox2.Text = Request.QueryString["fid"].ToString();

            DataTable dt = bll.GetEmployee(this.TextBox2.Text);
            if (dt != null)
            {
               this.TextBox3.Text  = dt.Rows[0][1].ToString();
               this.TextBox4.Text  = dt.Rows[0][2].ToString();
               this.TextBox5.Text  = dt.Rows[0][3].ToString();
               this.TextBox6.Text  = dt.Rows[0][4].ToString();
               this.TextBox7.Text  = dt.Rows[0][5].ToString();
               this.TextBox8.Text  = dt.Rows[0][6].ToString();              

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            EmployeeModel emp = new EmployeeModel();
            emp.Employee_Id = Convert.ToInt32(this.TextBox2.Text);
            emp.Employee_Name = this.TextBox3.Text.ToString();
            emp.Employee_Pwd = this.TextBox4.Text.ToString();
            emp.Employee_Phone = this.TextBox5.Text.ToString();
            emp.Employee_Addr = this.TextBox6.Text.ToString();
            emp.Employee_State = this.TextBox7.Text.ToString();
            emp.Employee_Remark = this.TextBox8.Text.ToString();
            if (bll.Update(emp) > 0)
            {
                Response.Write("<script>alert('修改成功!');location.href='Employee.aspx';</script>");
            }
           
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("Employee.aspx");
        }
    }
}